﻿using System.Configuration;

namespace MediaController.Configuration
{
    /// <summary>
    /// Singeltone object for configuration
    /// </summary>
    public class MediaControllerConfig
    {
        private static MediaControllerConfig _controllerConfig;


        public WatchConfiguration Watch { get; private set; }

        public AutoMovingConfiguration AutoMoving { get; private set; }

        public static MediaControllerConfig ControllerConfig
        {
            get
            {
                if (_controllerConfig == null)
                {
                    _controllerConfig = new MediaControllerConfig();
                }
                return _controllerConfig;
            }
        }

        public MediaControllerConfig()
        {
            Watch = new WatchConfiguration();
            AutoMoving = new AutoMovingConfiguration();
            Load();
        }

        public void Save()
        {
            var watch = ConfigurationManager.AppSettings["Watch"];
            var autoMoving = ConfigurationManager.AppSettings["AutoMoving"];

            AutoMoving.Serialize(autoMoving);
            Watch.Serialize(watch);
        }

        private void Load()
        {
            var watch = ConfigurationManager.AppSettings["Watch"];
            var autoMoving = ConfigurationManager.AppSettings["AutoMoving"];

            AutoMoving = AutoMoving.Deserialize(autoMoving);
            Watch = Watch.Deserialize(watch);
        }
    }
}
